package com.hhxy.practice;

import java.util.Scanner;
//寻找素数
public class SeekPrime {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入需要寻找的素数范围");
        int start = sc.nextInt();
        int end = sc.nextInt();
        int count = 0;//记录素数的个数
        for(int i=start;i<=end;i++){
            if(i==1){
                continue;
            }
            if(checkPrime(i)){
                System.out.println(i);
                count++;
            }
        }
        System.out.println(start+"~"+end+"之间共有"+count+"个素数");
    }
    //素数的检测
    private static boolean checkPrime(int i) {
        if(i<=0){
            return false;
        }
        for(int j=2;j<=Math.sqrt(i);j++){
            if(i%j==0){
                return false;
            }
        }
        return true;
    }
}
